﻿using LS.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using WebMatrix.WebData;

namespace LS.ModelLogicHelpers
{
    public class AccountLogicHelper
    {
        private LSDbContext db = new LSDbContext();
        public const string AadminRoleName = "Admin";
        public const string MemberRoleName = "Member";
        public void InitializerRole()
        {

        }

        public void AddMemberRoleForUser(string username)
        {
            if (!Roles.RoleExists(AadminRoleName))
                Roles.CreateRole(AadminRoleName);
            if (!Roles.RoleExists(MemberRoleName))
                Roles.CreateRole(MemberRoleName);
            Roles.AddUserToRole(username, MemberRoleName);
        }
        public void InitializeMember(string username)
        {
            AddMemberRoleForUser(username);
            var newMember = new Member()
            {
                UsrId = WebSecurity.GetUserId(username),
                UpdateDate = DateTime.UtcNow,
            };
            db.Members.Add(newMember);
            db.SaveChanges();
        }
    }
}